package org.rayken.trix.commons.game.runTypes;

import java.util.List;

import org.rayken.trix.commons.card.Card;
import org.rayken.trix.commons.game.Game;
import org.rayken.trix.commons.game.Player;
import org.rayken.trix.commons.game.Run;
import org.rayken.trix.commons.game.RunType;
import org.rayken.trix.commons.game.Trick;

public class KingOfHeartsRun extends Run {

	public KingOfHeartsRun(Game game, Player caller, boolean forced) {
		super(game, caller, forced);
	}

	static final int PENALTY_SCORE = 100;

	@Override
	public boolean isFinished() {
		if (super.tricks.size() == 0)
			return false;
		
		Trick lastTurn = super.tricks.get(tricks.size() - 1);
		if (lastTurn.isComplete() && lastTurn.getPlayForCard(Card.KING_HEARTS) != null)
			return true;

		return false;
	}

	@Override
	public void cardPlayed(Player player, Trick turn, Card cardPlayed) {
	
		if (turn.isComplete() && turn.isCardPlayed(Card.KING_HEARTS)) {
			Player victim = turn.getWiningPlay().getPlayer();
			int scoreToAdd = PENALTY_SCORE;

			if (forced)
				scoreToAdd *= 2;
			if (victim.equals(caller))
				scoreToAdd *= 2;

			addScore(victim, scoreToAdd);
		}
		deals.get(player).remove(cardPlayed);
	}

	@Override
	public List<Card> getAvailablePlayableCard(Player player, Trick turn) {
		return super.getAvailablePlayableCardDefault(player, turn);
	}

	@Override
	public RunType getType() {
		return RunType.THE_KING_OF_HEARTS;
	}

}
